<template>
  <div class="ListShow_container">
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图 -->
    <el-card>
      <!-- 搜索区域 -->
      <el-row :gutter="20">
        <el-col :span="8">
          <!-- 搜索与添加区域 -->
            <el-input placeholder="请输入商品名称"
            v-model="queryInfo.query" clearable @clear="getUserList">
            <el-button slot="append" icon="el-icon-search" @click="getUserList"></el-button>
          </el-input>
        </el-col>
        <el-col :span="3">
          
        </el-col>
      </el-row> 

      <!-- 展示数据区域 -->
      <el-table :data="userlist" stripe border >
        <!-- lable是标题  prop是内容-->
        <el-table-column type="index" label="序号"></el-table-column>
        <el-table-column label="姓名" prop="username" align="center"></el-table-column>
        <el-table-column label="邮箱" prop="email" align="center"></el-table-column>
        <el-table-column label="电话" prop="mobile" align="center"></el-table-column>
        <el-table-column label="角色" prop="role_name" align="center"></el-table-column>
        <el-table-column label="状态" prop="mg_state" align="center">
          ??未付款
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </el-card>
    
  </div>
</template>

<script>
export default {
  name:'ListShow',
  data(){
    return{
      // 获取用户列表的参数对象
      queryInfo:{
          query:'',
          // 当前的页数
          pagenum:1,
          // 当前每页显示多少条数据
          pagesize:2,
        },
        userlist:[],
        total:0
    }
  },
  created(){
    this.getUserList()
  },
  methods:{
    // 获取数据
    async getUserList(){
      const {data:res}= await this.$http.get('users',{params:this.queryInfo})
      if(res.meta.status !==200 ){
        return this.$message.error('获取列表失败！')
      }
      console.log(res);
      this.userlist=res.data.users
      this.total=res.data.total
    },

    // 监听pagesize改变的数据
    handleSizeChange(newSize){
      // console.log(newSize);
      this.queryInfo.pagesize=newSize
      // 重新获取数据
      this.getUserList()
    },
    // 监听页码改变的数据
    handleCurrentChange(newpage){
      // console.log(newpage);
      this.queryInfo.pagenum=newpage
      // 重新获取数据
      this.getUserList()
    }
  }
}
</script>

<style lang="less" scoped>

</style>